#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
    printf("当前进程 pid: %d \n" ,getpid());
    int i=100;
    pid_t pid=  fork();
    if(pid==0)
    {   
        i+=50;
        printf("子进程 pid: %d \n" ,getpid());
        printf("pid=%d ,当前进度pid  %d , 当前进程的父pid:%d\n",pid,getpid(),getppid());
        sleep(8);
        printf(" 子进程退出... i:%d \n",i);
        
        _exit(EXIT_FAILURE);
    }else{
        i-=80;
        printf("父进程 pid: %d \n" ,getpid());
       
        int over_status=0;
        //等待功能
        printf(" 父进程开始等待...\n");
        waitpid(pid,&over_status,0);
        //检测功能
        // while(1){
        //     sleep(1);
        //     int run_status = waitpid(pid,&over_status,WNOHANG);
             
        //     printf("子进程返回状态 %d. 子进程结束状态..%d\n",run_status,over_status);
             
        // }
        printf(" 父进程退出... i:%d \n",i);

    }
    

    return 0;
}
